package com.example.tcp.client.serde.impl;

import com.example.tcp.client.RetryTcpClient;
import com.example.tcp.client.serde.Serde;
import com.squareup.tape2.ObjectQueue;
import io.netty.buffer.Unpooled;

import java.io.IOException;
import java.io.OutputStream;

public class Tap2MessageSerde implements ObjectQueue.Converter<RetryTcpClient.Message> {
    @Override
    public RetryTcpClient.Message from(byte[] bytes) throws IOException {
        return new RetryTcpClient.ByteBufMessage(Unpooled.copiedBuffer(bytes));
    }

    @Override
    public void toStream(RetryTcpClient.Message message, OutputStream outputStream) throws IOException {
        outputStream.write(message.serialize());
    }
}
